<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/5/19
 * Time: 15:45
 */

namespace app\admin\controller;

use app\common\model\BasicArea;
use app\common\model\BusInquiry;
use app\common\model\Role;
use app\common\model\SalesCompany;
use app\common\model\SuppliersCompany;
use app\common\model\SysConfig;
use app\common\model\SysUser;

class Common extends Admin
{
    public function test()
    {
        $data = input();
        json_success_msg($data);
    }
    public function basedata(){
        $data = array();
        $roleModel = new Role();
        $data['role_list'] = $roleModel->field('role_id,role_name')->select();
        // 保险公司
        $companyModel = new SalesCompany();
        $data['company_list'] =  $companyModel->field('id,company_name')->select();
        // 供货商
        $suppliersCompanyModel = new SuppliersCompany();
        $data['suppliers_company_list'] =  $suppliersCompanyModel->field('id,suppliers_company_name')->where(['state'=>0])->select();
        $configModel = new SysConfig();
        $profit_rate =  $configModel->where(['name'=>'profit_rate'])->find();
        $data['profit_rate'] = $profit_rate['val']['content'];
        json_return_code($data);
    }

    public function getUserList(){
        $userModel = new SysUser();
        $userList = $userModel->field('user_id,true_name')->select();
        json_return_code($userList);
    }


    public function getSuppliersList(){
        $words = input('words','','trim');
        $param = ['state'=>0];
        if($words){
            $param['service_brand'] = ['like','%'.$words.'%'];
        }
        // 供货商
        $suppliersCompanyModel = new SuppliersCompany();
        $suppliers_company_list =  $suppliersCompanyModel->where($param)->field('id,suppliers_company_name')->select();

        json_return_code($suppliers_company_list);
    }

    public function getNamePhone()
    {
        $content_type = input('content_type');
        $word_type = input('word_type');
        $word = input('word','','trim');
        $model = new BusInquiry();
        $info = '';
        if($content_type === 'user'){
            if($word_type == 'name'){
                $info = $model->where(['bus_user_name'=>$word])->whereNotNull('bus_user_phone')->limit(1)->value('bus_user_phone');
            }else{
                $info = $model->where(['bus_user_phone'=>$word])->whereNotNull('bus_user_name')->limit(1)->value('bus_user_name');
            }
        }else{
            if($word_type == 'name'){
                $info = $model->where(['repair_company_name'=>$word])->whereNotNull('repair_company_phone')->limit(1)->value('repair_company_phone');
            }else{
                $info = $model->where(['repair_company_phone'=>$word])->whereNotNull('repair_company_name')->limit(1)->value('repair_company_name');
            }
        }
        json_return_code($info);
    }
}